import { createRouter, createWebHashHistory } from 'vue-router'
// const router = createRouter({
//   history: createWebHistory(import.meta.env.BASE_URL),
//   routes:
// })

const routes = [
    {path: '/',name: 'nav',component: () => import('@/views/NavView.vue'),
    children:[
      {name:'home',path:'/home',component:()=>import('@/views/HomeView.vue')},
      {path: '/store',name: 'store',component: () => import('@/views/StoreView.vue'),},
  ]},
    {path: '/main',name: 'main',component: () => import('@/views/MainView.vue'),
      children: [
        {path: 'contract', name: 'contract',component: () => import('@/views/ContractView.vue')},
        {path: 'upload', name: 'upload',component: () => import('@/views/UploadView.vue')},
        {path: 'student', name: 'student',component: () => import('@/views/StudentManagementView.vue')},
        {path: 'class', name: 'class',component: () => import('@/views/ClassManagementView.vue')},
        {path: 'attend', name: 'attend',component: () => import('@/views/AttendManagementView.vue')},
        {path: 'user', name: 'user',component: () => import('@/views/UserManagementView.vue')},
        {path: 'role', name: 'role',component: () => import('@/views/RoleManagementView.vue')},
        {path: 'menu', name: 'menu',component: () => import('@/views/MenuManagementView.vue')},
        {path: 'banner', name: 'banner',component: () => import('@/views/BannerManageView.vue')},
        {path: 'checkActivity', name: 'checkActivity',component: () => import('@/views/CheckActivityView.vue')},
        {path: 'checkAdvert', name: 'checkAdvert',component: () => import('@/views/CheckAdvertView.vue')},
        {path: 'checkColumn', name: 'checkColumn',component: () => import('@/views/CheckColumnView.vue')},
        {path: 'checkSeckillView', name: 'checkSeckillView',component: () => import('@/views/CheckSeckillView.vue')},
        {path: 'campusOrder', name: 'campusOrder',component: () => import('@/views/CampusOrderView.vue')},
        {path: 'courseOrder', name: 'courseOrder',component: () => import('@/views/CourseOrderView.vue')},
        {path: 'contract', name: 'contract',component: () => import('@/views/ContractView.vue')},
        {path: 'seckill', name: 'seckill',component: () => import('@/views/PublishSecondKillView.vue')},
      ]
    },
    {path: '/login',name: 'login',component: () => import('@/views/LoginView.vue'),},
    {path: '/file',name: 'file',component: () => import('@/views/FileView.vue')},
    // {path: '/user',name: 'user',component: () => import('@/views/UserManagementView.vue')},
    // {path: '/menu',name: 'menu',component: () => import('@/views/MenuManagementView.vue')},
    // {path: '/campusOrder',name: 'campusOrder',component: () => import('@/views/CampusOrderView.vue')},
    // {path: '/courseOrder',name: 'courseOrder',component: () => import('@/views/CourseOrderView.vue')},
    {path: '/register',name: 'register',component: () => import('@/views/RegisterView.vue')},
  ]


const router = createRouter({
  history: createWebHashHistory(),
  routes: routes
})

router.beforeEach((to, from, next) => {
  const whiteList = ['/', '/login'];
  const token = localStorage.getItem('token')
   next();
  // if (whiteList.includes(to.path)) {
  //   // 白名单中的路由，直接放行
  //
  // } else if (token) {
  //   // 已登录，放行
  //   next();
  // } else {
  //   // 未登录，重定向到登录页
  //   next('/login');
  // }
})

export default router
